{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# VNA control"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**scikit-rf** has a few virtual instrument classes, located in the `skrf.vi` module. This page demonstrates the basic control of a PNA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from skrf.vi import vna \n",
    "\n",
    "p =vna.PNA(\"TCPIP0::192.168.0.2::INSTR\")\n",
    "p.idn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ntwks =  p.get_network_all_meas()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "[k.plot_s_db(label = k.name) for k in ntwks]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Interactive"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from IPython.html.widgets import interact, interactive, fixed\n",
    "from IPython.html import widgets\n",
    "from IPython.display import clear_output, display, HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib\n",
    "matplotlib.use('nbagg')\n",
    "\n",
    "freq= p.frequency\n",
    "f_start = freq.start/1.e9\n",
    "f_stop = freq.stop/1.e9\n",
    "f_npts = 101\n",
    "f_range =(f_start, f_stop,1)\n",
    "f_range\n",
    "\n",
    "def dummy(f_start=f_start,f_stop=f_stop):\n",
    "    p.frequency = rf.Frequency(f_start, f_stop,f_npts,'ghz')\n",
    "    p.get_twoport().plot_s_db()\n",
    "    \n",
    "\n",
    "interact(dummy,f_start=f_range,f_stop=f_range)\n"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
